package com.test.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/5/3.
 */
@Controller
public class ExcelExport extends BaseController{

    @RequestMapping("toExcel")
    public String toExcel(){
        return "excel";
    }

    @RequestMapping("export")
    public void export(HttpServletRequest request, HttpServletResponse response) throws Exception {
        String[] excelTitle = {"姓名","年龄"};
        List<Map<Integer, String>> excelContent = new ArrayList<Map<Integer, String>>();
        Map<Integer, String> map = new HashMap<Integer, String>();
        map.put(1,"roger");
        map.put(2,"18");
        excelContent.add(map);

        Map<Integer, String> map2 = new HashMap<Integer, String>();
        map2.put(1,"james");
        map2.put(2,"18");
        excelContent.add(map2);

        ExcelUtils excelUtils = new ExcelUtils();
        excelUtils.exportExcel(excelTitle, excelContent, null, "测试");
    }

    @RequestMapping("export2")
    public void export2(HttpServletRequest request, HttpServletResponse response) throws Exception {
        String startDate = request.getParameter("year");
        String endDate = request.getParameter("month");
        System.out.println("startDate:"+startDate+" endDate:"+endDate);
        List<String> titles = new ArrayList<String>();
        titles.add("姓名");
        titles.add("年龄");

        List<List<String>> lines = new ArrayList<List<String>>();
        List<String> content = new ArrayList<String>();
        content.add("roger");
        content.add("18");
        lines.add(content);
        List<String> content2 = new ArrayList<String>();
        content2.add("james");
        content2.add("18");
        lines.add(content2);
        export(titles, lines, "测试", request, response);
    }
}
